define(function(require, exports, module) {
    "use strict";
    var $ = require("$"),
        app = require("dist/application/app"),
        config = app.config,
        method = app.method;
        var jscolor=require("jscolor");
        require("./appplug"); 
    $(".js_link_select").change(function(event) {
        var $target=$(".js_custom_link"),type=$(this).find("option:selected").data("type");
        if(type=="custom"){
            $target.removeClass('hide');
        }else{
            $target.addClass('hide');
        }
    });
    jscolor.install();
    $(".js_create_config_btn").click(function(event) {
        var $this=$(this),$textarea=$(".js_content_temp"),value=$textarea.val().replace(/[\r\n]/g, "");
        var result=value.match(/\{\{([^}]+)}}/g),$config=$(".js_config_area");
        if(result){
            $config.html("");
            for(var i=0,len=result.length;i<len;i++){
                var list=result[i].replace(/[\{\}]/g, "");
                if(list=="first.DATA"){
                    $config.append(template("js_first_temp",{"label":list}));
                }else if(list=="remark.DATA"){
                    $config.append(template("js_remark_temp",{"label":list}));
                }else{
                    if(list.indexOf("DATA")>0){
                        $config.append(template("js_other_temp",{"label":list}));
                    }
                }
            }
            jscolor.init();
        }
    });
    $(document).on("click",".js_add_custom",function(){
        var $this=$(this),$target=$this.closest('.form-group');
        $(template("js_custom_temp",{})).insertBefore($target);
        jscolor.init();
    });
    $(document).on("click",".js_del_custom",function(){
        var $this=$(this),$target=$this.closest('.form-group');
        $target.remove();
    });
    $(document).on("change",".js_order_oper",function(){
        var $this=$(this),$target=$(".js_tips_date_set"),
        $select=$(".js_tips_date_select"),select=$this.val();
        if(select){
            $target.removeClass('hide');
            var type=$this.find("option:selected").data("type");
            $select.find("option").removeAttr("selected");
            $select.find("option").addClass('hide');
            $select.find("option[data-type="+type+"]").removeClass('hide');
        }else{
            $target.addClass('hide');
        }
    });
    
 });